#ifndef TWO_PLAYER_H
#define TWO_PLAYER_H

#include <QWidget>
//双人模式，大部分和单人模式函数基本一致
const int Block_Size_dou=25;//方块大小
const int Row_dou=20;//行数
const int Col_dou=12;//列数
const int Area_Out_dou=25;//计分板等边距

enum Direction_dou{
    UP_dou,
    DOWN_dou,
    LEFT_dou,
    RIGHT_dou,
    SPACE_dou
};
//方向操控器件

struct Border_dou{
    int up_bound_dou;
    int down_bound_dou;
    int left_bound_dou;
    int right_bound_dou;
};

struct Border_dou1{
    int up_bound_dou1;
    int down_bound_dou1;
    int left_bound_dou1;
    int right_bound_dou1;
};

//边界信息

struct Block_Point_dou{
    int x_pos_dou;
    int y_pos_dou;
};

//坐标信息
namespace Ui {
class Two_Player;
}

class Two_Player : public QWidget
{
    Q_OBJECT

public:
    explicit Two_Player(QWidget *parent = nullptr);
    ~Two_Player();
    void Init_Game_dou();
    void Start_Game_dou();
    void Game_Over_dou();


    void Block_Reset_dou();
    void Block_Reset_dou1();
    void Block_Move_dou(Direction_dou dir);
    void Block_Move_dou1(Direction_dou dir);
    void Block_Revolve_dou(int Block_use[4][4]);
    void Block_Crate_dou(int Block_use[4][4], int Block_ID);
    void Border_Side_dou(int Block_use[4][4],Border_dou &border);
    void Block_Stable_dou(int x, int y);
    void Block_Stable_dou1(int x, int y);
    bool If_Crash_dou(int x, int y, Direction_dou);
    bool If_Crash_dou1(int x, int y, Direction_dou);
    bool isOver_dou();
public:
    void paintEvent(QPaintEvent *event) override;
    void timerEvent(QTimerEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;
    void closeEvent(QCloseEvent *event) override;
signals:
    void close_dou();
private:
    Ui::Two_Player *ui;
private:
    bool is_Over_dou=false;
    //由于双人模式，需要创建两个对象和对应的函数
    int Game_Area_dou[Row_dou][Col_dou], Game_Area_dou1[Row_dou][Col_dou];
    Block_Point_dou Pos_Block_dou, Pos_Block_dou1;
    int Now_Block_dou[4][4], Now_Block_dou1[4][4];
    Border_dou Now_border_dou, Now_border_dou1;
    int Next_Block_dou[4][4], Next_Block_dou1[4][4];
    bool Is_Stable_dou, Is_Stable_dou1;
    int Game_Timer_dou;
    int Paint_Timer_dou;
    int Down_Time_dou;
    int Refresh_Time_dou;
    int score_dou, score_dou1;
};

#endif // TWO_PLAYER_H
